package com.tencreat.service.mall.impl;

import java.time.LocalDateTime;
import java.util.List;

import cn.hutool.extra.cglib.CglibUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tencreat.common.core.domain.model.ReqIdParam;
import com.tencreat.common.core.domain.model.ReqIdsParam;
import com.tencreat.domain.mall.MallDeliverAddress;
import com.tencreat.domain.mall.dto.MallShipAddressDTO;
import com.tencreat.mapper.mall.MallDeliverAddressMapper;
import com.tencreat.service.mall.IMallDeliverAddressService;
import org.springframework.stereotype.Service;

/**
 * 平台/供应商发货地址Service业务层处理
 *
 * @Author tencreat
 * @Company: 深圳腾创互联科技有限公司
 * @link: https://tencreat.com
 * @Date 2022-12-08
 */
@Service
public class MallDeliverAddressServiceImpl extends ServiceImpl<MallDeliverAddressMapper, MallDeliverAddress> implements IMallDeliverAddressService {


    /**
     * 查询平台/供应商发货地址
     *
     * @param id 平台/供应商发货地址ID
     * @return 平台/供应商发货地址
     */
    @Override
    public MallDeliverAddress selectMallDeliverAddressById(ReqIdParam id) {
        return baseMapper.selectById(id.getId());
    }

    /**
     * 查询平台/供应商发货地址列表
     *
     * @param mallDeliverAddress 平台/供应商发货地址
     * @return 平台/供应商发货地址
     */
    @Override
    public List<MallDeliverAddress> selectMallDeliverAddressList(MallDeliverAddress mallDeliverAddress) {
        return baseMapper.selectList(Wrappers.query(mallDeliverAddress));
    }

    /**
     * 新增平台/供应商发货地址
     *
     * @param mallDeliverAddress 平台/供应商发货地址
     * @return 结果
     */
    @Override
    public int insertMallDeliverAddress(MallDeliverAddress mallDeliverAddress) {
        mallDeliverAddress.setCreateTime(LocalDateTime.now());
        return baseMapper.insert(mallDeliverAddress);
    }

    /**
     * 修改平台/供应商发货地址
     *
     * @param mallDeliverAddress 平台/供应商发货地址
     * @return 结果
     */
    @Override
    public int updateMallDeliverAddress(MallDeliverAddress mallDeliverAddress) {
        mallDeliverAddress.setUpdateTime(LocalDateTime.now());
        return baseMapper.updateById(mallDeliverAddress);
    }

    /**
     * 批量删除平台/供应商发货地址
     *
     * @param ids 需要删除的平台/供应商发货地址ID
     * @return 结果
     */
    @Override
    public int deleteMallDeliverAddressByIds(ReqIdsParam ids) {
        return baseMapper.deleteBatchIds(ids.getId());
    }

    /**
     * 删除平台/供应商发货地址信息
     *
     * @param id 平台/供应商发货地址ID
     * @return 结果
     */
    @Override
    public int deleteMallDeliverAddressById(ReqIdParam id) {
        return baseMapper.deleteById(id.getId());
    }

    @Override
    public int shipAddress(MallShipAddressDTO dto) {
        MallDeliverAddress mallDeliverAddress = new MallDeliverAddress();
        CglibUtil.copy(dto,mallDeliverAddress);
        mallDeliverAddress.setDeliverType(1);
        mallDeliverAddress.setCreateTime(LocalDateTime.now());
        return baseMapper.insert(mallDeliverAddress);
    }

    @Override
    public String refundAddress(Long addressId) {
        return baseMapper.refundAddress(addressId);
    }
}
